<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>demo02</title>
</head>
<body>
  <!-- 封装变量 -->
  <script>
    var mul = (function() {
      var cache = {};

      var calculate = function() {
        var a = 1;
        for(var i = 0, len = arguments.length; i < len; i++) {
          a *= arguments[i];
        }
        return a;
      }

      return function() {
        var args = Array.prototype.join.call(arguments, ',');
        if(cache[args]) {
          return cache[args];
        }
        console.log(args)
        return cache[args] = calculate.apply(null, arguments);
      }

    })();

    console.log(mul(1, 2, 3))
    console.log(mul(1, 2, 3))
    console.log(mul(2, 2, 3))
    console.log(mul(2, 2, 3))

    // 延续局部变量

    // var report = function(src) {
    //   var img = new Image();
    //   img.src = src;
    // }

    var report = (function() {
      var imgs = [];

      return function(src) {
        var img = new Image();
        imgs.push(img);
        img.src = src
      }
    })();
    
    report('........')
  </script>
</body>
</html>